package com.yu.crm.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yu.crm.domain.pojo.CrmBlacklistUser;
import com.yu.crm.service.CrmBlacklistUserService;
import com.yu.crm.utils.EigenValue;
import com.yu.crm.utils.FileUtil;
import com.yu.crm.utils.MultipartFileToFile;
import com.yxzz.common.BaseController;
import com.yxzz.common.helper.DateHelpers;
import com.yxzz.common.helper.ResourceConfigHelpers;
import com.yxzz.common.helper.valid.ValidatorHelpers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

/**
 * <p>
 * 黑名单用户表 前端控制器
 * </p>
 *
 * @author ct
 * @since 2020-07-01
 */
@Api(tags = "黑名单用户")
@RestController
@RequestMapping("/crm-blacklist-user")
public class CrmBlacklistUserController implements BaseController<CrmBlacklistUser> {
    @Autowired
    CrmBlacklistUserService crmBlacklistUserService;

    @ApiOperation(value = "新增或更新")
    @Override
    @PostMapping(value = "/save-or-update")
    public void saveOrUpdate(@Valid CrmBlacklistUser entity, BindingResult bindingResult) {
        ValidatorHelpers.notEmpty(entity.getUsername(), "姓名不能为空");
        ValidatorHelpers.notEmpty(entity.getType(), "黑名单分类不能为空");
        ValidatorHelpers.notEmpty(entity.getUserFaceUrl(), "人脸照片不能为空");

        // 人脸特征
        if (entity.getCertificateEigen() == null) {
            entity.setCertificateEigen(EigenValue.extractFeatureImageUrl(entity.getUserFaceUrl()));
        }
        ValidatorHelpers.validateParams(bindingResult);
        crmBlacklistUserService.saveOrUpdate(entity);

    }

    @ApiOperation(value = "删除")
    @Override
    @DeleteMapping(value = "/remove-by-id/{id}")
    public void removeById(Long id) {
        crmBlacklistUserService.removeById(id);
    }

    @ApiOperation(value = "根据id获取")
    @Override
    @GetMapping(value = "/get-by-id/{id}")
    public CrmBlacklistUser getById(Long id) {
        return crmBlacklistUserService.getById(id);
    }


    @ApiOperation(value = "分页查询")
    @Override
    @GetMapping(value = "/list")
    public IPage<CrmBlacklistUser> list(Page<CrmBlacklistUser> page, CrmBlacklistUser queryInfo) {
        return crmBlacklistUserService.list(page, queryInfo);
    }

    @ApiOperation(value = "上传文件")
    @PostMapping(value = "/pic")
    public String file(MultipartFile file) {

        return FileUtil.uploadPictures(file);


    }


}

